<% layout('/views/layouts/default.html', {title: 'UserInfo List', libs: ['validate']}){ %>
<section class="content-header">
	<h1>用户 管理</h1>
	<ol class="breadcrumb">
		<li>
			<a href="/user/listPage"><button class="btn btn-xs jfedit btn-default">刷新</button></a>&nbsp;
			<a href="/user/addPage"><button class="btn btn-xs jfedit btn-primary">新增</button></a>
		</li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-body">
					<table id="example" class="table table-bordered table-hover" style="width:100%">
						<thead>
							<tr>
								<th>id</th>
								<th>用户名</th>
								<th>密码(密文)</th>
								<th>角色</th>
								<th>微信昵称</th>
								<th>真名</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody></tbody>
						<tfoot>
							<tr>
								<th>id</th>
								<th>用户名</th>
								<th>密码(密文)</th>
								<th>角色</th>
								<th>微信昵称</th>
								<th>真名</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
	</div>
</section>
<% } %>

<script>
$(document).ready(function() {
	$('#example').DataTable( {
		"order": [[ 0, "desc" ]],
		"ajax": "/user/list",
		"columns": [
			{ "data": "id" },
			{ "data": "username" },
			{ "data": "password" },
			{ "data": "roleName" },
			{ "data": "wxNickName" },
			{ "data": "realName" },
			{ "data": "state" },
			{ "data": "state" ,"width":"200px"}
		],
		"aoColumnDefs":[
		{//倒数第一列
			"targets":-1,
			"bSortable": false,
			render: function(data, type, row) {
				var html = '<a href="/user/editUserRolePage?id='+row.id+'"><button class="btn btn-xs jfedit btn-info" value="'+row.id+'">角色</button></a>&nbsp;&nbsp;&nbsp;&nbsp;'
				+'<a href="/user/editPage?id='+row.id+'"><button class="btn btn-xs jfedit btn-info" value="'+row.id+'">编辑</button></a>&nbsp;&nbsp;&nbsp;&nbsp;'
				+'<button onclick="delFun('+row.id+')" id="delButton" class="btn btn-xs btn-danger jfdelete">删除</button>';
				return html;
			}
		}]
	});
});

function delFun(id){
	if(confirm("确定删除嘛？")){
		$.ajax({
			url:"/user/delete?id=" + id,
			success:function(data){
				alert(data.resMsg);
				window.location.href="/userInfo/listPage";
			}
		});
	};
}
</script>
